package com.woniumall.web;

import com.woniumall.pojo.Address;
import com.woniumall.pojo.User;
import com.woniumall.service.AddressService;
import com.woniumall.service.UserService;
import com.woniumall.service.impl.AddressServiceImpl;
import com.woniumall.service.impl.UserServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @auther linke
 * @create 2021-11-03 14:31
 */
@WebServlet("/address/*")
public class AddressServlet extends BaseServlet {
    private AddressService addressService = new AddressServiceImpl();
    /**
     * 根据用户id查询所属地址详情
     * @param request
     * @param response
     * @throws Exception
     */
    public void findAllByUserId(HttpServletRequest request, HttpServletResponse response) throws Exception {
        //获取userid
        User user = (User)request.getSession().getAttribute("user");
        int userId = user.getId();
        List<Address> addressList = addressService.findAllByUserId(userId);
        responseUtil(response,addressList);
    }
    public void findById(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String addressid = request.getParameter("addressid");//获取地址id

        Address address = addressService.findById(Integer.parseInt(addressid));//获取地址信息
        addressService.del(Integer.parseInt(addressid));
        responseUtil(response,address);//响应address
    }


}
